package com.dfba.Homework8;

import java.util.ArrayList;

public class GouWuChe {
    //在购物车类GouWuChe中定义ArrayList成员变量,用于保存购物车中的商品
    ArrayList<Goods> list=new ArrayList<>();
    public void addGoods(Goods goods){
          list.add(goods);
        System.out.println(goods.getName()+"商品加入成功");
    }
    public void showGoods() {
        System.out.println("您选购的商品为：");
        for (Goods goods : list) {
            System.out.println(goods.getId()+","+goods.getName()+","+goods.getPrice());
        }
    }
    public void total() {
        double yuanJia = 0;
        double xianJia = 0;
        for (Goods goods : list) {
            yuanJia+=goods.getPrice();
            if(goods instanceof EGoods){
                xianJia += (goods.getPrice() * 0.88);
            } else {
                xianJia += goods.getPrice();
            }
        }
        System.out.println("原  价为: " + yuanJia + "元");
        System.out.println("折后价为: " + xianJia + "元");
    }

}
